!define APPNAME	"ES581.4 USB to CAN Gateway"
!define COMPANYNAME "Robert Bosch"

!define VERSIONMAJOR 1
!define VERSIONMINOR 1
!define VERSIONBUILD 1

!define HELPURL "http://www.google.com"
!define UPDATEURL "http://www.google.com"
!define ABOUTURL "http://www.google.com"
!define INSTALLSIZE 100
RequestExecutionLevel admin

InstallDir "$PROGRAMFILES\${COMPANYNAME}\${APPNAME}"

LicenseData "license.rtf"

Name "${COMPANYNAME}-${APPNAME}"
outFile "ES581.4_installer.exe"

!include LogicLib.nsh

page license
page directory
page instfiles


!macro VerifyUserIsAdmin

UserInfo::GetAccountType
pop $0
${IF} $0 != "admin"
		messageBox mb_iconstop "Admin rights required"
		setErrorLevel 740
		quit
${ENDIF}

!macroend

function .onInit
	setShellVarContext all
	!insertmacro VerifyUserIsAdmin
functionEnd
	
Section "install"

	SetOutPath $INSTDIR
	
	File "test.txt"
	;File "logo.ico"
	
	WriteUninstaller "$INSTDIR\uninstall.exe"
	
	CreateDirectory "$SMPROGRAMS\${COMPANYNAME}"
	;CreateShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk"
	
	;Registry info
	
	WriteRegStr HKLM "Software\${COMPANYNAME} ${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
	WriteRegStr HKLM "Software\${COMPANYNAME} ${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
	WriteRegStr HKLM "Software\${COMPANYNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
	WriteRegStr HKLM "Software\${COMPANYNAME} ${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
	;WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayIcon" "$\"$INSTDIR\logo.ico$\""
	WriteRegStr HKLM "Software\${COMPANYNAME} ${APPNAME}" "Publisher" "$\"${COMPANYNAME}$\""
	WriteRegStr HKLM "Software\${COMPANYNAME} ${APPNAME}" "HelpLink" "$\"${HELPURL}$\""
	WriteRegStr HKLM "Software\${COMPANYNAME} ${APPNAME}" "URLUpdateInfo" "$\"${UPDATEURL}$\""
	WriteRegStr HKLM "Software\${COMPANYNAME} ${APPNAME}" "URLInfoAbout" "$\"${ABOUTURL}$\""
	WriteRegStr HKLM "Software\${COMPANYNAME} ${APPNAME}" "DisplayVersion" "$\"${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}$\""
	WriteRegDWORD HKLM "Software\${COMPANYNAME} ${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
	WriteRegDWORD HKLM "Software\${COMPANYNAME} ${APPNAME}" "VersionMinor" ${VERSIONMINOR}
	# There is no option for modifying or repairing the install
	WriteRegDWORD HKLM "Software\${COMPANYNAME} ${APPNAME}" "NoModify" 1
	WriteRegDWORD HKLM "Software\${COMPANYNAME} ${APPNAME}" "NoRepair" 1
	# Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
	WriteRegDWORD HKLM "Software\${COMPANYNAME} ${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
sectionEnd
 
# Uninstaller
 
function un.onInit
	SetShellVarContext all
 
	#Verify the uninstaller - last chance to back out
	MessageBox MB_OKCANCEL "Permanantly remove ${APPNAME}?" IDOK next
		Abort
	next:
	!insertmacro VerifyUserIsAdmin
functionEnd
 
section "uninstall"
 
	# Remove Start Menu launcher
	delete "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk"
	# Try to remove the Start Menu folder - this will only happen if it is empty
	rmDir "$SMPROGRAMS\${COMPANYNAME}"
 
	# Remove files
	delete "$INSTDIR\test.txt"
	;delete $INSTDIR\logo.ico
 
	# Always delete uninstaller as the last action
	delete "$INSTDIR\uninstall.exe"
 
	# Try to remove the install directory - this will only happen if it is empty
	rmDir "$INSTDIR"
 
	# Remove uninstaller information from the registry
	DeleteRegKey HKLM "Software\${COMPANYNAME} ${APPNAME}"
sectionEnd

